package xixirupan.tmgp.tencent.com.vmeim.ui.beautyshop.model;

import android.util.Log;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import xixirupan.tmgp.tencent.com.vmeim.config.URLConfig;
import xixirupan.tmgp.tencent.com.vmeim.retrofit.IBeautyShopR;

/**
 * Created by lenovo on 2016/10/19.
 */

public class GetIndexTopData  {

    int curPager =1;
    List<Object> lists =new ArrayList<>();
    //创建该类时初始化接口对象

    //接口对象传递数据的方法
    public void getData(final IGetIndexTopData topData, final int curPager)
    {
        this.curPager =curPager;
        //curPager == 1
        if (curPager == 1)
        {
            //创建retrofit对象
            Retrofit retrofit =new Retrofit.Builder()
                    .baseUrl(URLConfig.Url.KEY_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();

            //创建网络连接的接口的独享
            IBeautyShopR netconn = retrofit.create(IBeautyShopR.class);

            //获取网络连接对象
            Call<BeautyShopBean> call= netconn.getIndexTopdata();

            //对象异步请求网络访问
            call.enqueue(new Callback<BeautyShopBean>() {
                @Override
                public void onResponse(Call<BeautyShopBean> call, Response<BeautyShopBean> response) {
                    Log.i("4444","---------->"+99999);
                    BeautyShopBean body1 = response.body();
                    ///
                    Log.i("YYYY","+========>"+body1.toString());
                    ShopDataBean body = body1.getData();
                    List<Nav1BannersBaen> nav1Banners = body.getNav1Banners();
                    List<TopBannersBaen> topBanners = body.getTopBanners();
                    lists.add(topBanners);//数据源1
                    lists.add(nav1Banners); //数据源2

                    List<Map<String,String>> _lists =new ArrayList<Map<String, String>>();
                    Map<String,String> map1 =new HashMap<String, String>();
                    map1.put("imgUrl", URLConfig.URL_1);
                    map1.put("click", URLConfig.URL_cLICK1);
                    _lists.add(map1);

                    Map<String,String> map2 =new HashMap<String, String>();
                    map2.put("imgUrl", URLConfig.URL_2);
                    map2.put("click", URLConfig.URL_cLICK2);
                    _lists.add(map2);

                    Map<String,String> map3 =new HashMap<String, String>();
                    map3.put("imgUrl", URLConfig.URL_3);
                    map3.put("click", URLConfig.URL_cLICK3);
                    _lists.add(map3);

                    Map<String,String> map4 =new HashMap<String, String>();
                    map4.put("imgUrl", URLConfig.URL_4);
                    map4.put("click", URLConfig.URL_cLICK4);
                    _lists.add(map4);

                    lists.add(_lists);//数据源3
                    List<LiveListBaen> liveList = body.getLiveList();
                    lists.add(liveList);//数据源4
                    ShopMainDataBiz biz =new ShopMainDataBiz();
                    biz.getBottomData(new ShopMainDataBiz.PostMainDataListener() {
                        @Override
                        public void postData(List<Object> _lists) {
                            for (int i = 0; i < _lists.size(); i++) {
                                if (_lists.get(i) instanceof String)
                                {

                                    lists.add(_lists.get(i));//第五种数据源 String类型
                                }else {
                                    //第六种数据源 集合类型
                                    lists.add(_lists.get(i));
                                }

                            }
                            //利用数据传递的接口对象把数据源传递出去
                            //  topData.getAdGrideData(_lists);  //传递数据源4

                            topData.postData(lists);

                        }
                    },curPager);



                }

                @Override
                public void onFailure(Call<BeautyShopBean> call, Throwable t) {
                    //  java.lang.NumberFormatException: Expected an int but was 3616221000 at line 1 column 9077 path $.data.liveList[8].liveDuration
                    //一定要记得打印异常
                    Log.i("-------","请求任务失败"+t.getMessage());
                }
            });}
        else {

            ShopMainDataBiz biz =new ShopMainDataBiz();
            biz.getBottomData(new ShopMainDataBiz.PostMainDataListener() {
                @Override
                public void postData(List<Object> _lists) {
                    for (int i = 0; i < _lists.size(); i++) {
                        if (_lists.get(i) instanceof String)
                        {

                            lists.add(_lists.get(i));//第五种数据源 String类型
                        }else {
                            //第六种数据源 集合类型
                            lists.add(_lists.get(i));
                        }

                    }
                    //利用数据传递的接口对象把数据源传递出去
                    //  topData.getAdGrideData(_lists);  //传递数据源4

                    topData.postData(lists);

                }
            },curPager);

        }



    }

}
